package logic

import (
	"context"
	"encoding/json"
	"go-zero/user-jwt/internal/svc"
	"go-zero/user-jwt/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
	return &GetUserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetUserInfoLogic) GetUserInfo(req *types.UserInfoReq) (resp *types.UserInfoResp, err error) {
	// todo: add your logic here and delete this line
	userId, _ := l.ctx.Value("uid").(json.Number).Int64()
	roleId, _ := l.ctx.Value("roleId").(json.Number).Int64()
	uid := int(userId)
	rid := int(roleId)
	return &types.UserInfoResp{
		Id:       uid,
		RoleId:   rid,
		Username: "张三",
		Age:      20,
	}, nil
}
